using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;


using Material.Object;
using Material.DAL;
namespace Material.Entity
{
	public class TblTransPenjBarangDTLEntity
	{
		private Accessor accessor;
		private string connString;

		public TblTransPenjBarangDTLEntity (string _connString)
		{
			 this.connString = _connString;
		}

		public int Insert(TblTransPenjBarangDTL tbltranspenjbarangdtl)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPenjBarangDTL_Insert";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add("@IdTransDTL" ,tbltranspenjbarangdtl.IdTransDTL );
			 accessor.Add("@IdTransHDR" ,tbltranspenjbarangdtl.IdTransHDR );
			 accessor.Add("@IdBarang" ,tbltranspenjbarangdtl.IdBarang );
			 accessor.Add("@Jumlah" ,tbltranspenjbarangdtl.Jumlah );
			 accessor.Add("@HargaJual" ,tbltranspenjbarangdtl.HargaJual );
			 accessor.Add("@TotalHarga" ,tbltranspenjbarangdtl.TotalHarga );
			 accessor.Add("@CreatedDate" ,tbltranspenjbarangdtl.CreatedDate );
			 accessor.Add("@CreatedBy" ,tbltranspenjbarangdtl.CreatedBy );
			 accessor.Add("@ModifiedDate" ,tbltranspenjbarangdtl.ModifiedDate );
			 accessor.Add("@ModifiedBy" ,tbltranspenjbarangdtl.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Update(TblTransPenjBarangDTL tbltranspenjbarangdtl)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPenjBarangDTL_Update";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransDTL" ,tbltranspenjbarangdtl.IdTransDTL );
			 accessor.Add(@"IdTransHDR" ,tbltranspenjbarangdtl.IdTransHDR );
			 accessor.Add(@"IdBarang" ,tbltranspenjbarangdtl.IdBarang );
			 accessor.Add(@"Jumlah" ,tbltranspenjbarangdtl.Jumlah );
			 accessor.Add(@"HargaJual" ,tbltranspenjbarangdtl.HargaJual );
			 accessor.Add(@"TotalHarga" ,tbltranspenjbarangdtl.TotalHarga );
			 accessor.Add(@"CreatedDate" ,tbltranspenjbarangdtl.CreatedDate );
			 accessor.Add(@"CreatedBy" ,tbltranspenjbarangdtl.CreatedBy );
			 accessor.Add(@"ModifiedDate" ,tbltranspenjbarangdtl.ModifiedDate );
			 accessor.Add(@"ModifiedBy" ,tbltranspenjbarangdtl.ModifiedBy );

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public int Delete(TblTransPenjBarangDTL tbltranspenjbarangdtl)
		{
			 int result = -1;
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPenjBarangDTL_Delete";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransDTL" ,tbltranspenjbarangdtl.IdTransDTL);

			 result = Excutor.ExecuteNonQuery(accessor);
			 if (result != -1)
				 accessor.CommitTransaction();
			 else
				 accessor.RollBackTransaction();
			 return result;
		}

		public TblTransPenjBarangDTL GetDataByID(TblTransPenjBarangDTL tbltranspenjbarangdtl)
		{
			 TblTransPenjBarangDTL result = new TblTransPenjBarangDTL();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPenjBarangDTL_SelectByID";
			 accessor.CommandType = CommandType.StoredProcedure;
			 accessor.Add(@"IdTransDTL" ,tbltranspenjbarangdtl.IdTransDTL);

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 result.IdTransDTL = rdr.GetInt32(0);
						 result.IdTransHDR = rdr.GetInt32(1);
						 result.IdBarang = rdr.GetInt32(2);
						 result.Jumlah = rdr.GetInt32(3);
						 result.HargaJual = rdr.GetDecimal(4);
						 result.TotalHarga = rdr.GetDecimal(5);
						 result.CreatedDate = rdr.GetDateTime(6);
						 result.CreatedBy = rdr.GetString(7);
						 result.ModifiedDate = rdr.GetDateTime(8);
						 result.ModifiedBy = rdr.GetString(9);
					  }
			}
			 return result;
		}

		public List<TblTransPenjBarangDTL> GetDataAll()
		{
			 List<TblTransPenjBarangDTL> result = new List<TblTransPenjBarangDTL>();
			 accessor = new Accessor(true, connString);
			 accessor.CommandText = "TblTransPenjBarangDTL_SelectAll";
			 accessor.CommandType = CommandType.StoredProcedure;

			 SqlDataReader rdr = Excutor.GetDataReader(accessor);
			 if (rdr.HasRows)
			 {
				 while (rdr.Read())
					 {
						 TblTransPenjBarangDTL obj = new TblTransPenjBarangDTL();
						 obj.IdTransDTL = rdr.GetInt32(0);
						 obj.IdTransHDR = rdr.GetInt32(1);
						 obj.IdBarang = rdr.GetInt32(2);
						 obj.Jumlah = rdr.GetInt32(3);
						 obj.HargaJual = rdr.GetDecimal(4);
						 obj.TotalHarga = rdr.GetDecimal(5);
						 obj.CreatedDate = rdr.GetDateTime(6);
						 obj.CreatedBy = rdr.GetString(7);
						 obj.ModifiedDate = rdr.GetDateTime(8);
						 obj.ModifiedBy = rdr.GetString(9);
						 result.Add(obj);
					  }
			}
			 return result;
		}

	}
}
